import {Component, OnInit} from '@angular/core';
import {ListAftApplyOrderComponent} from '../list-aft-apply-order.component';
import {Zero3Option} from '../../../../../frame/enum/zero3-option';
import {AftApplyOrderCondition} from '../../aft-apply-order.type';
import * as fa from '@fortawesome/free-solid-svg-icons';
import {ListOrdOrderComponent} from "../../../../order-management/ord-order/list-ord-order/list-ord-order.component";

@Component({
    selector: 'app-search-list-aft-apply-order',
    templateUrl: './search-list-aft-apply-order.component.html',
    styleUrls: ['./search-list-aft-apply-order.component.css']
})
export class SearchListAftApplyOrderComponent implements OnInit {

    // func = this.upper.func;

    zero3Option = Zero3Option;

    condition = new AftApplyOrderCondition();

    list = () => {
        this.listAftApplyOrder.func.list.click(null);
    };
    extend = {
        keyup: (event) => {
            // T-O-D-O 51 # err
            if (event.keyCode > 32 || event.keyCode === 8) {
                this.listAftApplyOrder.func.list.click(event);
            }
        },
        condition: {
            afterSaleNo: {
                icon: fa.faPen,
                nickname: '售后单号',
                value: () => {
                    return this.condition.afterSaleNo;
                },
                keyup: (event) => {
                    this.condition.afterSaleNo = event.target.value;
                    this.extend.keyup(event);
                }
            },
            receiverName: {
                icon: fa.faPen,
                nickname: '收件人',
                value: () => {
                    return this.condition.receiverName;
                },
                keyup: (event) => {
                    this.condition.receiverName = event.target.value;
                    this.extend.keyup(event);
                }
            },
            receiverPhone: {
                icon: fa.faPen,
                nickname: '手机号',
                value: () => {
                    return this.condition.receiverPhone;
                },
                keyup: (event) => {
                    this.condition.receiverPhone = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serCreateTime: {
                icon: fa.faCalendar,
                nickname: '申请售后时间段',
                value: () => {
                    // return `${this.condition.createTimeOUTSET} - ${this.condition.createTimeFINISH}`;
                    return this.condition.serCreateTime;
                },
                focus: (event) => {
                    const dataOF = event.target.value.toString().split(' ~ ');
                    this.condition.createTimeOUTSET = dataOF[0];
                    this.condition.createTimeFINISH = dataOF[1];
                    this.listAftApplyOrder.func.list.click(event);
                },
                blur: (event) => {
                    this.extend.condition.serCreateTime.focus(event);
                }
            },
            serAuditState: {
                icon: fa.faList,
                nickname: '状态',
                // value: '',
                change: (event) => {
                    // this.condition.serAuditList = [];
                    // console.log(this.field.serAudit.value);
                    // this.condition.serAuditList = this.field.serAudit.value.split(',');
                    console.log(this.condition.serAuditStateList);
                }
            },
            serMoney: {
                icon: fa.faDollarSign,
                nickname: '≥ 退款金额 ≥',
                leftNumber: {
                    value: null,
                    keyUp: (event) => {
                        this.condition.serMoneyLeft = event.target.value.toString();
                        this.extend.condition.serMoney.leftNumber.value = this.condition.serMoneyLeft;
                        this.list();
                    },
                    focus: (event) => {
                    },
                    blur: (event) => {
                        this.extend.condition.serMoney.leftNumber.keyUp(event);
                    }
                },
                    rightNumber: {
                        value: null,
                        keyUp: (event) => {
                            this.condition.serMoneyRight = event.target.value.toString();
                            this.extend.condition.serMoney.rightNumber.value = this.condition.serMoneyRight;
                            this.list();
                        },
                        focus: (event) => {
                        },
                        blur: (event) => {
                            this.extend.condition.serMoney.rightNumber.keyUp(event);
                        }
                    }
                },
                orderStatus: {
                    icon: fa.faUserAlt,
                    nickname: '订单状态',
                    value: () => {
                        return this.condition.orderStatus;
                    },
                    keyup: (event) => {
                        this.condition.orderStatus = event.target.value;
                        this.extend.keyup(event);
                    }
                },
            },
        };

    constructor(public listAftApplyOrder: ListAftApplyOrderComponent) {
        listAftApplyOrder.search = this;
        this.condition.serMoneyLeft = '';
        this.extend.condition.serMoney.leftNumber.value = this.condition.serMoneyLeft;
    }

    ngOnInit() {
    }

}
